import Layout from '@/layout'
// import router from '@/router/index'

export function loadMenu (menuList) {
	let routeList = [];
	for (var i = 0; i < menuList.length; i++) {
		var hidden = menuList[i].hasOwnProperty('hide') ? false : menuList[i].hide;
		var data = {
			path: menuList[i].path,
			component: Layout,
			name: menuList[i].name,
			meta: {
				title: menuList[i].meta.title,
				icon: menuList[i].meta.icon
			},
			children: [],
			hidden: hidden,
		}
		if (menuList[i].redirect != null) {
			data = {
				path: menuList[i].path,
				component: Layout,
				hidden: hide,
				redirect: menuList[i].redirect,
				name: menuList[i].name,
				meta: {
					title: menuList[i].meta.title,
					icon: menuList[i].meta.icon,
				},
				children: []
			}

		}
		if (menuList[i].hasOwnProperty('children') && menuList[i].children != null && menuList[i].children.length > 0) {
			console.log(1111)
			for (var j = 0; j < menuList[i].children.length; j++) {
				let componentName = menuList[i].children[j].component;
				var childrenData = {
					path: menuList[i].children[j].path,
					name: menuList[i].children[j].name,
					component: (resolve) => require([`@/views/${componentName}`], resolve),//import(`@/views/${componentName}.vue`),
					meta: {
						title: menuList[i].children[j].meta.title,
						icon: menuList[i].children[j].meta.icon,
						hide: menuList[i].children[j].meta.hide,
					}
				}
				data.children.push(childrenData);
			}
		}
		routeList.push(data);
	}

	return routeList;
}

